package spring.cloud.tasks.executor.name_space.executor.task.task_item.task_item_execute_info;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import spring.cloud.tasks.common.node.TaskNodePath;
import spring.cloud.tasks.executor.name_space.executor.task.TaskExecutor;
import spring.cloud.tasks.executor.name_space.executor.task.task_item.TaskItemExecuteInfoService;
import spring.cloud.tasks.executor.name_space.executor.task.task_listener.TaskListenerHolder;

@Slf4j
@Setter
@Getter
public class TaskItemExecuteInfoNeedReportListenerHolder extends TaskListenerHolder {
    public boolean isShutdown = false;

    public TaskItemExecuteInfoService taskItemExecuteInfoService;

    public TaskItemExecuteInfoNeedReportListenerHolder(TaskExecutor taskExecutor) {
        super(taskExecutor);
        taskItemExecuteInfoService = taskExecutor.getTaskItemExecuteInfoService();
    }

    @Override
    public void start() {
        taskExecutorNodeCacheOrTreeCacheManager.addTreeCacheListener(TaskNodePath.getTaskNodePath(taskId, TaskItemExecuteInfoNeedReportNode.NEED_REPORT_NODE), 0, new TaskItemExecuteInfoNeedReportListener(this));
    }

    @Override
    public void stop() {
        super.stop();
        isShutdown = true;
        taskExecutorNodeCacheOrTreeCacheManager.closeTreeCache(TaskNodePath.getTaskNodePath(taskId, TaskItemExecuteInfoNeedReportNode.NEED_REPORT_NODE), 0);
    }

}
